package me.zhengjie.modules.website.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import io.swagger.annotations.ApiOperation;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiResponse;
import io.swagger.annotations.ApiResponses;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;
import me.zhengjie.modules.website.domain.AccessLogs;
import me.zhengjie.modules.website.service.AccessLogsService;
import org.springframework.data.domain.Pageable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.GetMapping;
import me.zhengjie.modules.website.domain.PageResult;
import java.util.List;

/**
 *
 *
 * @author system
 * @since 2024-12-02 16:18:43
 */
@RestController
@RequestMapping("/api/accessLogs")
@Api(tags = " 网页-访问日志")
public class AccessLogsController {

    @Autowired
    private AccessLogsService accessLogsService;

    /**
     * 分页查询
     *
     * @param params
     * @return
     */
    @ApiOperation(value = "分页查询",notes = "分页查询",produces = "application/json")
    @ApiResponses({@ApiResponse(code = 200, message = "查询成功")})
    @PostMapping("/findPage")
    public ResponseEntity<PageResult<AccessLogs>> findPage(@RequestBody AccessLogs params, Pageable pageable) {
        PageResult<AccessLogs> result = accessLogsService.findPage(params, pageable);
        return ResponseEntity.ok(result);
    }
    /**
     * 列表查询
     *
     * @param params
     * @return
     */
    @ApiOperation(value = "列表查询",notes = "列表查询",produces = "application/json")
    @ApiResponses({@ApiResponse(code = 200, message = "查询成功")})
    @PostMapping("/findList")
    public ResponseEntity<List<AccessLogs>> findList(@RequestBody AccessLogs params) {
        List<AccessLogs> result = accessLogsService.findList(params);
        return ResponseEntity.ok(result);
    }

    /**
     * 查询
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "查询", notes = "查询详情")
    @ApiResponses({@ApiResponse(code = 200, message = "查询成功")})
    @GetMapping("findById/{id}")
    public ResponseEntity<AccessLogs> findById(@PathVariable("id") Long id) {
        AccessLogs accessLogs = accessLogsService.findById(id);
        return ResponseEntity.ok(accessLogs);
    }

    /**
     * 新增
     *
     * @param accessLogs
     * @return
     */
    @ApiOperation(value = "新增", notes = "新增数据")
    @ApiResponses({@ApiResponse(code = 200, message = "操作成功")})
    @PostMapping("/insert")
    public ResponseEntity<AccessLogs> insert( @Validated  @RequestBody AccessLogs accessLogs) {
        AccessLogs result = accessLogsService.insert(accessLogs);
        return ResponseEntity.ok(result);
    }

    /**
     * 修改
     *
     * @param accessLogs
     * @return
     */
    @ApiOperation(value = "修改", notes = "修改数据")
    @ApiResponses({@ApiResponse(code = 200, message = "操作成功")})
    @PutMapping("/update")
    public ResponseEntity<AccessLogs> update( @Validated  @RequestBody AccessLogs accessLogs) {
        AccessLogs result = accessLogsService.update(accessLogs);
        return ResponseEntity.ok(result);
    }

    /**
     * 删除
     *
     * @param id
     * @return
     */
    @ApiOperation(value = "删除", notes = "删除数据")
    @DeleteMapping("delete/{id}")
    public ResponseEntity<Void> delete(@PathVariable("id") Long id) {
        accessLogsService.delete(id);
        return ResponseEntity.ok(null);
    }

}